package com.xzp.bams.dao;

import java.util.Calendar;

public interface IDao<T, K> {
    public boolean insert(T t);

    public T selectOne(Long id, String password);

    public T selectOne(Long id);

    public K selectAll();

    public default boolean update(T t) {
        return false;
    }

    /**
     * 获取id
     */
    public Long getId();

    public void setId(Long id);

    public default Long createId() {
        String idStr = getId().toString();
        int year = Integer.parseInt(idStr.substring(8, 12));
        int month = Integer.parseInt(idStr.substring(12, 14));
        String count = idStr.substring(14);
        Calendar c = Calendar.getInstance();
        int nowYear = c.get(Calendar.YEAR);
        int nowMonth = c.get(Calendar.MONTH) + 1;
        if (year != nowYear || month != nowMonth) {
            year = nowYear;
            month = nowMonth;
            count = "0001";
        }
        if (count.equals("9999")) {
            count = "0001";
            System.out.println("您好，本月开卡名额已用完，请下个月再来");
            return -1L;
        }
        String str = "";
        if (month < 10) {
            str = "86215021" + year + "0" + month + count;
        } else {
            str = "86215021" + year + month + count;
        }

        Long id = Long.valueOf(str);
        this.setId(id + 1);
        return id;
    }

}
